﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AGHFiraPlayer.Strategies
{
    abstract public class AbstractStrategy : IStrategy 
    {
        public static int MAX_APPLICABILITY = 100;
        protected AGHDriver driver;
        protected List<RobotController> involvedRobots;
        protected StrategyType type;
        protected int currentApplicability;

        private List<RobotController> unoccupiedRobots = new List<RobotController>();

        public void flagChoosenRobots()
        {
            foreach (RobotController robot in involvedRobots) {
                robot.isUsedInStrategy = true;
            }
        }
        //trzeba pamietac aby w konstruktorach do strategi ustawiac liste robots na odpowiedni size - by involv dobrze zwracał
        public int involvesPlayers()
        {
            return involvedRobots.Count;
        }
        public StrategyType getStrategyType()
        {
            return type;
        }
        public List<RobotController> getInvolvedRobots()
        {
            return involvedRobots;
        }

        public override string ToString()
        {
            String name = base.ToString();
            return name.Substring(name.LastIndexOf('.') + 1);
        }

        public void setCurrentApplicability(int applicability)
        {
            this.currentApplicability = applicability;
        }

        public int getCurrentApplicability()
        {
            return this.currentApplicability;
        }

        public AbstractStrategy(ref AGHDriver driver) {
            this.driver = driver;
        }

        public List<RobotController> getUnoccupiedRobots()
        {
            unoccupiedRobots.Clear();

            foreach (RobotController robot in driver.Robots)
                if (!robot.isUsedInStrategy)
                    unoccupiedRobots.Add(robot);

            return unoccupiedRobots;
        }

        public void clearCachedValues()
        {
            involvedRobots.Clear();
            currentApplicability = 0;
            foreach (RobotController robot in involvedRobots)
            {
                robot.isUsedInStrategy = false;
            }
        }

        public AbstractStrategy() {}

        public abstract void execute();
        public abstract int applicabilityLevel(ref List<IStrategy> choosenStrategies);
    }
}
